<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>slibc: slibc/stdlib.h File Reference</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">slibc
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="dir_4d4a740b65ecc1faa3510c186d2f00c5.html">slibc</a>      </li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a> &#124;
<a href="#var-members">Variables</a>  </div>
  <div class="headertitle">
<div class="title">stdlib.h File Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p>Contains those _s functions that were added to C99's /usr/include/stdlib.h.  
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &quot;./base_.h&quot;</code><br/>
<code>#include &quot;<a class="el" href="errno_8h_source.html">./errno.h</a>&quot;</code><br/>
<code>#include &quot;<a class="el" href="stddef_8h_source.html">./stddef.h</a>&quot;</code><br/>
</div>
<p><a href="stdlib_8h_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr><td colspan="2"><h2><a name="func-members"></a>
Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="el" href="stdlib_8h.html#a8bf1b3817b7b2ccf6509574183f347e6">constraint_handler_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="stdlib_8h.html#a5fedeb6856ec1477ecc1c2ecc212d210">set_constraint_handler_s</a> (<a class="el" href="stdlib_8h.html#a8bf1b3817b7b2ccf6509574183f347e6">constraint_handler_t</a> handler)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">The set_constraint_handler function sets a user-specified constraint handler.  <a href="#a5fedeb6856ec1477ecc1c2ecc212d210"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a5f7c65f13b04de4b1b9685481dd75c1b"></a><!-- doxytag: member="stdlib.h::abort_handler_s" ref="a5f7c65f13b04de4b1b9685481dd75c1b" args="(const char *restrict msg, void *restrict ptr, errno_t error)" -->
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="stdlib_8h.html#a5f7c65f13b04de4b1b9685481dd75c1b">abort_handler_s</a> (const char *restrict msg, void *restrict ptr, errno_t error)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">The abort handler gives out an errormessage on stderr before it ends the program with the function abort. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a69a3eae83a143f09ff7a1111db714ec5"></a><!-- doxytag: member="stdlib.h::ignore_handler_s" ref="a69a3eae83a143f09ff7a1111db714ec5" args="(const char *restrict msg, void *restrict ptr, errno_t error)" -->
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="stdlib_8h.html#a69a3eae83a143f09ff7a1111db714ec5">ignore_handler_s</a> (const char *restrict msg, void *restrict ptr, errno_t error)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">the ignore_handler_s is used to ignore constraint violations it does nothing <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">errno_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="stdlib_8h.html#ac8fafcc6bb7a1d060f0e6a1e87a66da0">getenv_s</a> (size_t *restrict len, char *restrict value, rsize_t maxsize, const char *restrict name)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">The getenv_s function gets the value of an environment variable.  <a href="#ac8fafcc6bb7a1d060f0e6a1e87a66da0"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">errno_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="stdlib_8h.html#a645354c8bb78f135fe95ed5420eedc69">qsort_s</a> (void *base, rsize_t nmemb, rsize_t size, int(*compar)(const void *x, const void *y, void *context), void *context)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">This function sorts an array in ascending order.  <a href="#a645354c8bb78f135fe95ed5420eedc69"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="stdlib_8h.html#a338a507f5f7e51bb8690391ae4f55aef">bsearch_s</a> (const void *key, const void *base, rsize_t nmemb, rsize_t size, int(*compar)(const void *, const void *, void *context), void *context)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">This function performs a binary search of a sorted array.  <a href="#a338a507f5f7e51bb8690391ae4f55aef"></a><br/></td></tr>
<tr><td colspan="2"><h2><a name="var-members"></a>
Variables</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">SLIBC_BEGIN_DECLS typedef void(*&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="stdlib_8h.html#a8bf1b3817b7b2ccf6509574183f347e6">constraint_handler_t</a> )(const char *restrict msg, void *restrict ptr, errno_t error)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Definition of callback-type constraint_handler_t.  <a href="#a8bf1b3817b7b2ccf6509574183f347e6"></a><br/></td></tr>
</table>
<hr/><a name="details" id="details"></a><h2>Detailed Description</h2>
<div class="textblock"><p>Contains those _s functions that were added to C99's /usr/include/stdlib.h. </p>
</div><hr/><h2>Function Documentation</h2>
<a class="anchor" id="a338a507f5f7e51bb8690391ae4f55aef"></a><!-- doxytag: member="stdlib.h::bsearch_s" ref="a338a507f5f7e51bb8690391ae4f55aef" args="(const void *key, const void *base, rsize_t nmemb, rsize_t size, int(*compar)(const void *, const void *, void *context), void *context)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void* <a class="el" href="stdlib_8h.html#a338a507f5f7e51bb8690391ae4f55aef">bsearch_s</a> </td>
          <td>(</td>
          <td class="paramtype">const void *&#160;</td>
          <td class="paramname"><em>key</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const void *&#160;</td>
          <td class="paramname"><em>base</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">rsize_t&#160;</td>
          <td class="paramname"><em>nmemb</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">rsize_t&#160;</td>
          <td class="paramname"><em>size</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int(*)(const void *, const void *, void *context)&#160;</td>
          <td class="paramname"><em>compar</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">void *&#160;</td>
          <td class="paramname"><em>context</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>This function performs a binary search of a sorted array. </p>
<p>The array (given by base, nmemb and size) is searched for a member that is the same as the object pointed to by key.</p>
<dl class="user"><dt><b>Runtime-constraints:</b></dt><dd>A runtime-constraint violation occurs if <ul>
<li><em>nmemb</em> or <em>size</em> is greater than <em>RSIZE_MAX</em> </li>
<li>if <em>nmemb</em> &gt; 0 and (<em>key</em>, <em>base</em> or <em>comparison</em> are null pointers)</li>
</ul>
</dd></dl>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">key</td><td>points to the object to be matched </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">base</td><td>points to the start of the array </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">nmemb</td><td>specifies the number of elements in the array </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">size</td><td>gives the size of an individual array argument </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">compar</td><td>a pointer to the comparison function </td></tr>
    <tr><td class="paramdir">[in,out]</td><td class="paramname">context</td><td>may hold a user-defined value or Null. This value will be supplied as an extra-argument to the comparison function.</td></tr>
  </table>
  </dd>
</dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>A pointer to a matching element of the array NULL if no match is found or there is a runtime-constraint violation </dd></dl>
<dl class="see"><dt><b>See also:</b></dt><dd>bsearch </dd></dl>

</div>
</div>
<a class="anchor" id="ac8fafcc6bb7a1d060f0e6a1e87a66da0"></a><!-- doxytag: member="stdlib.h::getenv_s" ref="ac8fafcc6bb7a1d060f0e6a1e87a66da0" args="(size_t *restrict len, char *restrict value, rsize_t maxsize, const char *restrict name)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">errno_t <a class="el" href="stdlib_8h.html#ac8fafcc6bb7a1d060f0e6a1e87a66da0">getenv_s</a> </td>
          <td>(</td>
          <td class="paramtype">size_t *restrict&#160;</td>
          <td class="paramname"><em>len</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">char *restrict&#160;</td>
          <td class="paramname"><em>value</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">rsize_t&#160;</td>
          <td class="paramname"><em>maxsize</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *restrict&#160;</td>
          <td class="paramname"><em>name</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>The getenv_s function gets the value of an environment variable. </p>
<p>Developers often make wrong assumptions about the size of environment variables. Since a local attacker can set environment variables, the environment has to be considered evil as every other input. The getenv_s functions forces the programmer to supply a maximum buffer size.</p>
<dl class="user"><dt><b>Runtime-constraints:</b></dt><dd>A runtime-constraint violation occurs if <ul>
<li>name is a null pointer </li>
<li>maxsize is zero or greater than RSIZE_MAX </li>
<li>value shall not be a null pointer. In case of a runtime-constriant violation, the a non-zero <em>len</em> is dereferenced and set to zero.</li>
</ul>
</dd></dl>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
  <table class="params">
    <tr><td class="paramdir">[out]</td><td class="paramname">len</td><td>If len is not Null, the integer pointed to by len will be set to the length of the variable's value (one needs a buffer with length + 1 for storing the string) </td></tr>
    <tr><td class="paramdir">[out]</td><td class="paramname">value</td><td>contains the environment variable's value on success </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">maxsize</td><td>the size of the buffer pointed to by value </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">name</td><td>the name of the environment variable to search for</td></tr>
  </table>
  </dd>
</dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>Zero when the enviroment variable was found and successfully stored in the buffer pointed to by value. Non-zero otherwise.</dd></dl>
<dl class="user"><dt><b>Usage Example:</b></dt><dd><div class="fragment"><pre class="fragment">            <span class="keywordtype">char</span> env_value[255];
            <a class="code" href="stdlib_8h.html#ac8fafcc6bb7a1d060f0e6a1e87a66da0" title="The getenv_s function gets the value of an environment variable.">getenv_s</a>(NULL, env_value, <span class="keyword">sizeof</span>(env_value), <span class="stringliteral">&quot;PATH&quot;</span>);
</pre></div></dd></dl>
<dl class="see"><dt><b>See also:</b></dt><dd>getenv </dd></dl>

</div>
</div>
<a class="anchor" id="a645354c8bb78f135fe95ed5420eedc69"></a><!-- doxytag: member="stdlib.h::qsort_s" ref="a645354c8bb78f135fe95ed5420eedc69" args="(void *base, rsize_t nmemb, rsize_t size, int(*compar)(const void *x, const void *y, void *context), void *context)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">errno_t <a class="el" href="stdlib_8h.html#a645354c8bb78f135fe95ed5420eedc69">qsort_s</a> </td>
          <td>(</td>
          <td class="paramtype">void *&#160;</td>
          <td class="paramname"><em>base</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">rsize_t&#160;</td>
          <td class="paramname"><em>nmemb</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">rsize_t&#160;</td>
          <td class="paramname"><em>size</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int(*)(const void *x, const void *y, void *context)&#160;</td>
          <td class="paramname"><em>compar</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">void *&#160;</td>
          <td class="paramname"><em>context</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>This function sorts an array in ascending order. </p>
<p>The array is sorted according to the specified comparison function. Besides performing several runtime-checks (see rcs), the only difference is that the comparison function accepts an additional argument for the caller's use.</p>
<dl class="user"><dt><b>Runtime-constraints:</b></dt><dd>A runtime-constraint violation occurs if <ul>
<li><em>nmemb</em> or <em>size</em> is greater than <em>RSIZE_MAX</em> </li>
<li>if <em>nmemb</em> &gt; 0 and (<em>base</em> or <em>comparison</em> are null pointers)</li>
</ul>
</dd></dl>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in,out]</td><td class="paramname">base</td><td>points to the start of the array </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">nmemb</td><td>specifies the number of elements in the array </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">size</td><td>gives the size of an individual array argument </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">compar</td><td>a pointer to the comparison function </td></tr>
    <tr><td class="paramdir">[in,out]</td><td class="paramname">context</td><td>may hold a user-defined value or Null. This value will be supplied as an extra-argument to the comparison function. </td></tr>
  </table>
  </dd>
</dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>zero if there was no runtime-constraint violation. non-zero value otherwise.</dd></dl>
<dl class="see"><dt><b>See also:</b></dt><dd>qsort </dd></dl>

</div>
</div>
<a class="anchor" id="a5fedeb6856ec1477ecc1c2ecc212d210"></a><!-- doxytag: member="stdlib.h::set_constraint_handler_s" ref="a5fedeb6856ec1477ecc1c2ecc212d210" args="(constraint_handler_t handler)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="stdlib_8h.html#a8bf1b3817b7b2ccf6509574183f347e6">constraint_handler_t</a> <a class="el" href="stdlib_8h.html#a5fedeb6856ec1477ecc1c2ecc212d210">set_constraint_handler_s</a> </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="stdlib_8h.html#a8bf1b3817b7b2ccf6509574183f347e6">constraint_handler_t</a>&#160;</td>
          <td class="paramname"><em>handler</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>The set_constraint_handler function sets a user-specified constraint handler. </p>
<p>The constraint handler is called whenever a runtime constraint violation is detected. If, for example, a user calls strcpy_s(NULL, 0, source) the currently set runtime constraint handler will be invoked. The constraint handler is specific to each thread.</p>
<p>If the application does not set its own constraint handler, the default constraint handler is called. In our implementation the default constraint handler is abort_handler_s.</p>
<dl class="user"><dt><b>Runtime-constraints:</b></dt><dd>There are no runtime-constraints.</dd></dl>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">handler</td><td>a pointer to the new handler function</td></tr>
  </table>
  </dd>
</dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>the previously registered handler </dd></dl>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="stdlib_8h.html#a5f7c65f13b04de4b1b9685481dd75c1b" title="The abort handler gives out an errormessage on stderr before it ends the program with the function ab...">abort_handler_s</a>, <a class="el" href="stdlib_8h.html#a69a3eae83a143f09ff7a1111db714ec5" title="the ignore_handler_s is used to ignore constraint violations it does nothing">ignore_handler_s</a> </dd></dl>

</div>
</div>
<hr/><h2>Variable Documentation</h2>
<a class="anchor" id="a8bf1b3817b7b2ccf6509574183f347e6"></a><!-- doxytag: member="stdlib.h::constraint_handler_t" ref="a8bf1b3817b7b2ccf6509574183f347e6" args=")(const char *restrict msg, void *restrict ptr, errno_t error)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">SLIBC_BEGIN_DECLS typedef void(* <a class="el" href="stdlib_8h.html#a8bf1b3817b7b2ccf6509574183f347e6">constraint_handler_t</a>)(const char *restrict msg, void *restrict ptr, errno_t error)</td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Definition of callback-type constraint_handler_t. </p>
<p>All SLIBC-functions invoke the constraint handler in case of a constraint violation. </p>

</div>
</div>
</div><!-- contents -->


<hr class="footer"/><address class="footer"><small>
Generated on Wed Oct 31 2012 13:48:20 for slibc by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>
